﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dycox.ComponentModel;

namespace Dycox.Validation
{
    public class ValidationEventArgs : EventArgs
    {
        public ValidationEventArgs(object value)
            : this(value, null)
        {
        }

        public ValidationEventArgs(object value, PropertyValidationContext context)
        {
            _valueToValidate = value;
            _context = context;
        }

        private readonly object _valueToValidate;

        public object ValueToValidate
        {
            get { return _valueToValidate; }
        }

        public ValidationResult Result
        {
            get
            {
                if (_messages == null)
                    return ValidationResult.Ignore;

                return _messages.Success ? ValidationResult.Valid : ValidationResult.Invalid;
            }
        }

        private MessageSet _messages;

        public MessageSet Messages
        {
            get { return _messages; }
            set { _messages = value; }
        }


        private PropertyValidationContext _context;

        public PropertyValidationContext Context
        {
            get { return _context; }
        }

        public bool IsValid
        {
            get { return _messages == null || _messages.Success; }
        }
    }

    public delegate void ValidationEventHandler(object sender, ValidationEventArgs e);
}
